/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arg.deploy.webapp.tag.monitor.ctrl;

import com.arg.deploy.bean.Tag;
import com.arg.deploy.webapp.common.DeployRadioRenderer;
import static com.arg.deploy.webapp.common.DeployRowRenderer.LEFT_CELL_STYLE;
import org.apache.log4j.Logger;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Row;

/**
 *
 * @author sorasaks
 */
public class TagMonitorDiffMainRenderer extends DeployRadioRenderer {

    private static final Logger LOG = Logger.getLogger(TagMonitorDiffMainRenderer.class);

    private static final String STYLE_BACKGROUND_GRAY = "background-color: #ccc;";
    private static final String STYLE_BACKGROUND_WHITE = "background-color: white;";

    private String tempPath;
    private Integer diffNumber;
    private boolean isSwitch;

    public TagMonitorDiffMainRenderer() {
        diffNumber = 1;
        tempPath = "";
    }

    @Override
    protected void gridRender(Row row, Object o, int i) throws Exception {
        Tag object = (Tag) o;

        if (i != 0 && !object.getPath().trim().equalsIgnoreCase(tempPath)) {
            ++diffNumber;
            isSwitch = !isSwitch;
        }

        if (isSwitch) {
            row.setStyle(STYLE_BACKGROUND_GRAY);
        } else {
            row.setStyle(STYLE_BACKGROUND_WHITE);
        }

        object.setDiffNumber(diffNumber);
        tempPath = object.getPath().trim();

        appendCellInRow(row, createRadioInCell(object, LEFT_CELL_STYLE, diffNumber));
        appendCellInRow(row, createLabelInCell(String.valueOf(i + 1), CENTER_CELL_STYLE));
        appendCellInRow(row, createLabelInCell(object.getIssue(), LEFT_CELL_STYLE));
        appendCellInRow(row, createLabelInCell(object.getFilename(), LEFT_CELL_STYLE));
        appendCellInRow(row, createLabelInCell(object.getVersion(), LEFT_CELL_STYLE));
        appendCellInRow(row, createLabelInCell(object.getRevision(), LEFT_CELL_STYLE));
        appendCellInRow(row, createLabelInCell(object.getPath(), LEFT_CELL_STYLE));
        appendCellInRow(row, createLabelInCell(object.getUser().getUsername(), LEFT_CELL_STYLE));

        row.addEventListener(Events.ON_CLICK, new RowRadioEventListener(diffNumber));
    }
}
